package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.admin.domain.vo.ExperimentrequestVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.Experimentrequest;
import com.ruoyi.admin.service.IExperimentrequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验课申请Controller
 *
 * @author lin
 * @date 2024-04-27
 */
@RestController
@RequestMapping("/lab/experimentrequest")
public class ExperimentrequestController extends BaseController
{
    @Autowired
    private IExperimentrequestService experimentrequestService;

    /**
     * 查询实验课申请列表
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:list')")
    @GetMapping("/list")
    public TableDataInfo list(Experimentrequest experimentrequest)
    {
        startPage();
        experimentrequest.setTeacherId(SecurityUtils.getLoginUser().getUser().getUserId());
        List<ExperimentrequestVo> list = experimentrequestService.selectExperimentrequestList(experimentrequest);
        return getDataTable(list);
    }

    /**
     * 导出实验课申请列表
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:export')")
    @Log(title = "实验课申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Experimentrequest experimentrequest)
    {
        List<ExperimentrequestVo> list = experimentrequestService.selectExperimentrequestList(experimentrequest);
        ExcelUtil<ExperimentrequestVo> util = new ExcelUtil<ExperimentrequestVo>(ExperimentrequestVo.class);
        util.exportExcel(response, list, "实验课申请数据");
    }

    /**
     * 获取实验课申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(experimentrequestService.selectExperimentrequestByRequestId(requestId));
    }

    /**
     * 新增实验课申请
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:add')")
    @Log(title = "实验课申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Experimentrequest experimentrequest)
    {
        return toAjax(experimentrequestService.insertExperimentrequest(experimentrequest));
    }

    /**
     * 修改实验课申请
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:edit')")
    @Log(title = "实验课申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Experimentrequest experimentrequest)
    {
        return toAjax(experimentrequestService.updateExperimentrequest(experimentrequest));
    }

    /**
     * 删除实验课申请
     */
    @PreAuthorize("@ss.hasPermi('lab:experimentrequest:remove')")
    @Log(title = "实验课申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(experimentrequestService.deleteExperimentrequestByRequestIds(requestIds));
    }
}
